package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.dto.business.BusinessDTO;
import com.qk.dto.business.BusinessFollowDTO;
import com.qk.dto.business.BusinessInsertDTO;
import com.qk.dto.business.BusinessPoolDTO;
import com.qk.management.service.BusinessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 上官徵羽
 * @version 1.0
 * @since 2025-10-19 9:12
 */
@Slf4j
@RestController
@RequestMapping("/businesses")
public class BusinessController {
    @Autowired
    private BusinessService businessService;


    @GetMapping
    public Result listPage(BusinessDTO businessDTO) {
        return Result.success(businessService.listPage(businessDTO));
    }

    @PostMapping
    public Result insertBusiness(@RequestBody BusinessInsertDTO businessInsertDTO) {
        return Result.success(businessService.saveBusiness(businessInsertDTO));
    }

    @PutMapping("/assign/{businessId}/{userId}")
    public Result allocationBusiness(@PathVariable Integer businessId, @PathVariable Integer userId) {
        businessService.allocationBusiness(businessId, userId);
        return Result.success();
    }

    @PutMapping("/back/{id}")
    public Result outBusiness(@PathVariable Integer id) {
        businessService.outBusiness(id);
        return Result.success();
    }

    @PostMapping("/toCustomer/{id}")
    public Result toCustomer(@PathVariable Integer id){
        businessService.toCustomer(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        return Result.success(businessService.getBusinessById(id));
    }

    @PutMapping
    public Result businessFollow(@RequestBody BusinessFollowDTO businessFollowDTO) {
        businessService.businessFollow(businessFollowDTO);
        return Result.success();
    }

    @GetMapping("/pool")
    public Result businessPool(BusinessPoolDTO businessPoolDTO){
        return Result.success(businessService.businessPool(businessPoolDTO));
    }
}
